package com.ruoyi.common.filter;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class AntflowSetCurrentUserInfoFilter implements Filter {

    private static final Logger log = LoggerFactory.getLogger(AntflowSetCurrentUserInfoFilter.class);

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        if (servletRequest instanceof HttpServletRequest)
        {
            Object principal = SecurityUtils.getAuthentication().getPrincipal();
            if (principal instanceof LoginUser)
            {
                SysUser user = ((LoginUser) principal).getUser();
            }
        }

        filterChain.doFilter(servletRequest, servletResponse);
    }
}
